﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThridGroup.ERP.DTO;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace ThridGroup.ERP.ProductionSystem
{
    public class PendingTaskService : ApplicationService, PendingTaskIService
    {
        private readonly IRepository<PendingTasks, int> _pendingtaskrepository;
        public PendingTaskService(IRepository<PendingTasks, int> pendingtaskrepository)
        {
            _pendingtaskrepository = pendingtaskrepository;
        }

        public async Task<int> AddPendingTask(PendingTaskDTO pendingTask)
        {
            var list = ObjectMapper.Map<PendingTaskDTO,PendingTasks>(pendingTask);
            var result = await _pendingtaskrepository.InsertAsync(list);
            return result == null ? 0 : 1;
        }

        public async Task<int> DeletePendingTask(int pendingTaskId)
        {
            var Del = _pendingtaskrepository.DeleteAsync(c => c.Id == pendingTaskId);
            return Del == null ? 0 : 1;
        }

        public async Task<PendingTaskDTO> FanPendingTask(int pendingTaskId)
        {
            var list = await _pendingtaskrepository.FindAsync(c => c.Id == pendingTaskId);
            var result = ObjectMapper.Map<PendingTasks, PendingTaskDTO>(list);
            return result;
        }

        public async Task<List<PendingTaskDTO>> GetPendingTask(int pageIndex = 1, int pageSize = 10)
        {
            var list = await _pendingtaskrepository.GetListAsync();
            var result = ObjectMapper.Map<List<PendingTasks>, List<PendingTaskDTO>>(list);
            return result;
        }

        public async Task<int> UpdatePendingTask(PendingTaskDTO pendingTask)
        {
            var list = ObjectMapper.Map<PendingTaskDTO, PendingTasks>(pendingTask);
            var result = await _pendingtaskrepository.UpdateAsync(list);
            return result == null ? 0 : 1;
        }
    }
}
